﻿ <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReserveMenu1.aspx.cs" Inherits="WeChat.MenuReservation.ReserveMenu1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>菜单预定</title>
    <script src="../Script/rem.js"></script>
    <script src="../Script/jquery.min.js" type="text/javascript"></script>
    <script src="../Script/jquery-1.8.3.min.js?v=1.1"></script>
    <script src="../Scripts/mobiscroll-2.13.2.full.min.js?v=1.2"></script>
    <link href="../Content/mobiscroll-2.13.2.full.min.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <link rel="stylesheet" type="text/css" href="../css/page.css" />
    <link rel="stylesheet" type="text/css" href="../css/all.css" />
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/loaders.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/loading.css" />
    <link href="../Script/slick/slick.css" rel="stylesheet" />
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"/>
  <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
      <link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui.min.css"/>
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>  
    <script src="../Script/JquerySession.js"></script>
    <script type="text/javascript">
         $(window).load(function () {
             $(".loading").addClass("loader-chanage")
             $(".loading").fadeOut(300)
         })
         function submit() {    //点击确定按钮，把获取订单号，并把订单信息加入数据库 
            // var openid = $("#openid").text();
             $.ajax({
                 type: "post",
                 url: "../MenuReserveHandler.ashx",
                 data: { funcName: 'getGuid' },
                 success: function (result) {
                  
                     if (deductions == "是") {
                         window.location.href = "../JsSDK/WxPay/SubmitOrder.aspx?price=" + $("#sum").text() + "&OrderID=" + result + "&openid=" + openid;
                     }
                     var sum = $("#sum").text();
                     var languageJson = {};
                     $($(".name")).each(function () {
                             var m = $(this).parents(".bottom").find("[name='myCount']").text();      
                             languageJson[$(this).text()] = m;
                         });
                       
                         $.ajax({
                             type: "post",
                             url: "../MenuReserveHandler.ashx",
                             data: { json: JSON.stringify(languageJson), OrderId: result, date: "", type:"day", funcName: "AddOrderDetail" },
                         });
                   
                     var state = "";
                     if (deductions == "是") {
                         state = "1";
                     } else {
                         state = "2";
                     }
                     $.ajax({
                         type: "post",
                         url: "../MenuReserveHandler.ashx",
                         data: { OrderId: result, totalPrice: sum, openid: openid, state: state, funcName: "AddOrderList" },
                         success: function () {
                             if (deductions == "否") {
                                 //订餐成功
                                 $("#toast").css("display", "block");
                                 setTimeout(" window.location.href ='ReserveMenu1.aspx?openid=" + openid + "'", 2000)
                                 //$("#que").attr('href', "ReserveMenu1.aspx?openid=" + openid)
                             }
                         }
                     });
                 },
                 error: function () {
                     alert("异常！");
                 }
             });
         }
         //加入订单按钮
         function check(name, price) {
          
             var height = $(window).height();
             var cc = $("#determine").height();
             $(".am-share-sns").css("height", height - cc);
             var kssj = "";
             $.ajax({
                 type: "post",
                 url: "../MenuReserveHandler.ashx",
                 dataType: "json",
                 async: false,
                 data: { sdmc: "早餐", funcName: 'getTimeState' },
                 success: function (data) {
                     for (var i = 0; i < data.length; i++) {
                         kssj = data[i].kssj;
                     }
                   
                  
                 },
                 error: function () {
                     alert("异常！");
                 }
             });


             $.ajax({
                 type: "post",
                 url: "../MenuReserveHandler.ashx",
                 dataType: "json",
                 async: false,
                 data: { funcName: 'Notorder' },
                 success: function (data) {
                     var myarr = new Array();
                     for (var i = 0; i < data.length; i++) {
                         var remark = data[i].remark;
                         var str = data[i].notorderDate;
                         var tmp = /\d+(?=\+)/.exec(str);
                         var d = new Date(+tmp);
                         var notorderDate = d.getFullYear() + '/' + (+d.getMonth() + 1) + '/' + d.getDate();
                         var cc = new Date();
                         var a = cc.getFullYear() + "/" + (cc.getMonth() + 1) + "/" + cc.getDate() + " " + cc.getHours() + ":" + ( cc.getMinutes() + reservationtime) + ":" + cc.getSeconds();
                         debugger
                         if (notorderDate == name) {
                             $(".weui-dialog__bd").html("" + name + "不能订餐</br>" + remark + "");
                             $("#dialog").css("display", "block");
                             $('[name="' + name + '"] input[type="checkbox"]').prop('checked', false);
                             return;
                         }
                        else if (new Date(a) > new Date(name + " " + kssj)) {
                             $(".weui-dialog__bd").html("" + name + "不能订餐,已过预定时间");
                          
                             $("#dialog").css("display", "block");
                             $('[name="' + name + '"] input[type="checkbox"]').prop('checked', false);
                             return;
                         }

                     }
                     var tt = new Array();
                     $("[name='"+name+"']").each(function () {
                         tt.push($(this).text());
                     });
                   
                     if ($('[name="' + name + '"] input[type="checkbox"]').prop("checked")) {
                             if ($(".top").text() == "") {
                                 $(".sdetail").prepend('<div class="top clearfloat"><div class="you clearfloat fl"><span style="color:black">预定菜单</span></div></div><div class="bottom clearfloat"><p class="fl"><span name="order' + name + '" style="color:black" class="name">' + name + '</span> <span name="myPrice">￥' + price + '</span></p><div class="you clearfloat fr"><ul><li name="myCount"  style="width:4rem;">1</li></ul></div></div>');
                                 $("[name='count']").text(function (n, c) { return Number(c) + 1 });
                                 $("[name='sum']").text(function (n, c) { return Number(c) + Number(price) });
                             } else {
                                 $(".top").after('<div class="bottom clearfloat"><p class="fl"><span name="order' + name + '" style="color:black" class="name">' + name + '</span> <span name="myPrice">￥' + price + '</span></p><div class="you clearfloat fr"><ul><li name="myCount" style="width:4rem;">1</li></ul></div></div>');
                                 $("[name='count']").text(function (n, c) { return Number(c) + 1 });
                                 $("[name='sum']").text(function (n, c) { return Number(c) + Number(price) });
                             }
                       
                         if ($('.sdetail').find(".bottom").length > 0) {
                             $('#determine').attr("onclick", "submit()");
                         }
                     } else {
                 
                         if ($("[name='order" + name + "']").parents(".sdetail ").find(".bottom").length == 1) {
                             $("[name='order" + name + "']").parents(".bottom").siblings(".top").remove();
                             $("[name='order" + name + "']").parents(".bottom").remove();
                         }
                         else {
                             $("[name='order" + name + "']").parents(".bottom").remove();
                         }
                         $("[name='count']").text(function (n, c) { return Number(c) - 1 });
                         $("[name='sum']").text(function (n, c) { return Number(c) - Number(price) });

                     }
                    
                   
                 },
                 error: function () {
                     alert("异常！");
                 }
             });

      
         }
         //提交菜单加号功能
         function jiaBtn(na, p) {
             //debugger
             $("[name='" + na + "']").parents(".bottom").find("[name='myCount']").text(function (n, c) { return Number(c) + 1 });
             $("[name='count']").text(function (n, c) { return Number(c) + 1 });
             $("[name='sum']").text(function (n, c) { return Number(c) + Number(p) });
         };
         //提交菜单减号功能     
         function jianBtn(na, p) {
              var myPrice = $("[name='" + na + "']").parents(".bottom").find("[name='myPrice']");
              var myCount = $("[name='" + na + "']").parents(".bottom").find("[name='myCount']");
              var cc = myCount.text();
              var dd = myPrice.text().substring(1);
             if (Number(myCount.text()) > 1) {//所减数量大于1
                 myCount.text(function (n, c) { return Number(c) - 1 });
             } else {//所减数量小于1
                 if ($("[name='" + na + "']").parents(".sdetail ").find(".bottom").length==1)
                 {
                     $("[name='" + na + "']").parents(".bottom").siblings(".top").remove();
                     $("[name='" + na + "']").parents(".bottom").remove();
                 }
                 else {
                     $("[name='" + na + "']").parents(".bottom").remove();
                 }

                 if ($(".sdetail ").find(".bottom").length < 1)
                 {
                     $('.sdetail').prepend('<div class="top clearfloat"><div class="you clearfloat fl"><p class="tit"></p><span style="text-align:center;margin-top:20px;">没有商品，请选择</span></div></div>');
                     $('#determine').removeAttr("onclick");
                 }
             }
             $("[name='count']").text(function (n, c) { return Number(c) - 1 });
             $("[name='sum']").text(function (n, c) { return Number(c) - Number(myPrice.text().substring(1)) });
         };
         var Autos = new Array();
        
         var returntime = "";
         var reservationtime = "";
         var openid = "";
         var deductions = "";
         var dayprice = "";
         var reservationdays = "";
         $(function () {
             function getUrlParam(openid) {
                 var reg = new RegExp("(^|&)" + openid + "=([^&]*)(&|$)");
                 var r = window.location.search.substr(1).match(reg);
                 if (r != null) return unescape(r[2]); return null;
             }
             openid = getUrlParam('openid');
             $("#OrderList").attr('href', "OrderList.aspx?openid=" + openid+"&type=list2");
             $.ajax({
                 type: "post",
                 url: "../MenuReserveHandler.ashx",
                 dataType: "json",
                 async: false,
                 data: { funcName: 'getall' },
                 success: function (data) {
                     for (var i = 0; i < data.length; i++) {
                         reservationdays = data[i].reservationdays;
                         reservationtime = data[i].reservationtime;
                         returntime = data[i].returntime;
                         deductions = data[i].deductions;
                         dayprice = data[i].dayprice;
                         $.ajax({
                             type: "post",
                             url: "../MenuReserveHandler.ashx",
                             dataType: "json",
                             async: false,
                             data: { funcName: 'getdatatime', reservationdays: reservationdays },
                             success: function (data) {
                                 for (var i = 0; i < data.length; i++) {

                                     $("#seldate").append("<li>" + data[i] + "</li>");
                                 }

                             },
                             error: function () {
                                 alert("异常！");
                             }
                         });
                     }
                 },
                 error: function () {
                     alert("异常！");  
                 }
             });


         })
             $(document).ready(function () {
                 for (var i = 0; i < reservationdays; i++) {
                     var d = new Date();
                     var a = d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + (d.getDate() + i);
                
                     //$("#content").append('<div class="bottom clearfloat"><div class="lie clearfloat" style="padding:.7rem .2rem;"><div class="right clearfloat fl" style="width:100%;"><a href="#"></a><div class="xia clearfloat"><p class="tit" style="font-size:20px;"><span class="times">' + a + '</span> <span class="jifen fl over" style="float:none;font-size:20px;">￥' + dayprice + '</span><span class="fr db" name="add" id="add" style="margin-right:1rem;"  onclick="add(\'' + a + '\',' + dayprice + ')"><img src="../images/jia.png" /></span></p></div></div></div></div>');
                     $("#content").append('<div class="bottom clearfloat" style="margin:0"><div class="weui-cells weui-cells_checkbox" style="margin:0"><label class="weui-cell weui-check__label" for="s' + i + '" style="padding-bottom:0.4rem;padding-top:0.4rem;line-height:1.2rem;" name="' + a + '" onclick="check(\'' + a + '\',' + dayprice + ')"><div class="weui-cell__bd"><p class="tit" style="font-size:20px;">' + a + ' <span class="jifen fl over" style="float:none;font-size:20px;">￥' + dayprice + '</span></p></div> <div class="weui-cell__hd"><input type="checkbox" class="weui-check" name="checkbox1" id="s'+i+'"><i class="weui-icon-checked"></i></div></label></div></div>');

                     
                 }
             });
       
    </script>
</head>

  <div class="loading">
    <div class="loader">
        <div class="loader-inner pacman">

            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
</div>
<!--loading页结束-->
<body>
    <!--header star-->
    	<header class="mui-bar mui-bar-nav report-header box-s" id="header" style="width:100%; position:fixed; z-index:10">
			<a href="javascript:history.go(-1)"><i class="iconfont icon-fanhui fl"></i></a>
			<p>订餐系统</p>
            
	    </header>
   <%-- <header class="mui-bar mui-bar-nav" id="header" style="position:fixed">
        <a class="btn" href="javascript:history.go(-1)">
            <i class="iconfont icon-fanhui"></i>
        </a>
        <div class="top-sch-box flex-col">
            <div class="centerflex">
                <i class="fdj iconfont icon-sousuo"></i>
                <input type="text"  id="MenuName" value="" class="sch-txt" placeholder="输入您要搜索的菜品" />
            </div>
        </div>
        <a class="btn" href="#">
            <i class="iconfont icon-gouwuche"></i>
            <span>2</span>
        </a>
    </header>--%>
    <!--header end-->

    <div class="warp clearfloat">
        <div class="lists clearfloat">
   <div style="width:100%; height:0.4rem" id="tops">
           <div class="time clearfloat">
             
               <%-- <ul>
                   <li style="width: 5%;"><a href="javascript:history.go(-1)"><i class="iconfont icon-fanhui fl"></i></a></li> 
                    <li style="width: 30%;">选择日期</li>
                    <li style="width: 65% ;text-align:left;">
                        <ul id="seldate" style="text-align:center">
                            
                            </ul>
                   
                    </li>
                </ul>--%>
            </div>
               
          <div class="order-top clearfloat" style="height:0.3rem">
                 <%-- <ul>
                    <li class="clearfloat"><a href="#">时间段</a></li>
                    <li class="clearfloat" onclick="SelectTimeState('breakfast')" id="breakfast"><a href="#">早餐</a></li>
                    <li class="clearfloat" onclick="SelectTimeState('lunch')" id="lunch"><a href="#">中餐</a></li>
                    <li class="clearfloat" onclick="SelectTimeState('dinner')" id="dinner"><a href="#">晚餐</a></li>
                    <li class="clearfloat" onclick="SelectTimeState('midnightSnack')" id="midnightSnack"><a href="#">夜宵</a></li>
                </ul>--%>
           </div>
            </div>
            <div id="content" style="clear:both;padding-top:1.5rem;"></div>
         
             <%--   <div class="weui-cells weui-cells_checkbox"  style="margin:0">
                    <label class="weui-cell weui-check__label" for="s11" style="padding-bottom:0.4rem;padding-top:0.4rem" name="' + a + '" onclick="check(\'' + a + '\',' + dayprice + ')">
                        <div class="weui-cell__bd">
                            <p class="tit" style="font-size:20px;">' + a + ' 
                                <span class="jifen fl over" style="float:none;font-size:20px;">￥' + dayprice + '
                                </span></p></div>
                        <div class="weui-cell__hd">
                            <input type="checkbox" class="weui-check" name="checkbox1" id="s11">
                            <i class="weui-icon-checked"></i>
                        </div></label>
                </div>
            
           
                <div class="weui-cells weui-cells_checkbox"style="margin:0" >
                    <label class="weui-cell weui-check__label" for="s12" style="padding-bottom:0.4rem;padding-top:0.4rem" name="' + a + '" onclick="check(\'' + a + '\',' + dayprice + ')">
                        <div class="weui-cell__bd">
                            <p class="tit" style="font-size:20px;">' + a + ' 
                                <span class="jifen fl over" style="float:none;font-size:20px;">￥' + dayprice + '
                                </span></p></div>
                        <div class="weui-cell__hd">
                            <input type="checkbox" class="weui-check" name="checkbox1" id="s12">
                            <i class="weui-icon-checked"></i>
                        </div></label>
                </div>--%>
           
            <%--    <div class="bottom clearfloat">
            <div class="lie clearfloat">
						<a href="detail.html">
							<div class="tu clearfloat fl">
								<img src="upload/20.jpg"/>
							</div>
						</a>
						<div class="right clearfloat fl">
							<a href="detail.html">
								<p class="tit">美国阿拉斯加黑鳕鱼（冻黑鳕鱼）</p>
							</a>
							<div class="xia clearfloat">
								<a href="detail.html">
									<p class="jifen fl over">2998</p>
								</a>
								<span class="fr db" name="add" id="add"><img src="../images/jia.png"/></span>
							</div>
						</div>
					</div>
				</div>
           
            --%>
        </div>
         </div>
        <!--footerone star-->
        <div class="settlement clearfloat">
            <div class="zuo clearfloat fl box-s">
                共<span name="count">0</span>件  总金额：￥<span name="sum">0</span>
            </div>
            <a href="#" onclick="toshare()" class="fl db">提交订单
            </a>
        </div>
        <!--footerone end-->

        <!--这里是弹出购物车内容-->
        <div class="am-share">
            <div class="am-share-footer">
                <button class="share_btn">
                    <img src="../images/chahao.png" /></button>
            </div>
            <div class="am-share-sns box-s">
                <div class="sdetail clearfloat">
                   <%--  <div class="top clearfloat">
                        <div class="you clearfloat fl">
                              <span style="color:black">预定菜单</span>
                           
                          
                        </div>
                    </div>--%>
                  <%--  <div class="all">
                   
                    <div class="bottomall">
                        <p class="tit">午餐预定</p>
                         	<div class="bottom clearfloat">                   
                                
		     		<p class="fl">菜单1 <span name="myPrice">10</span></p>
		     		<div class="you clearfloat fr">
		     			<ul>
		     				<li name="jianBtn"><img src="../images/jian.jpg"/></li>
		     				<li name="myCount">1</li>
		     				<li name="jiaBtn"><img src="../images/jia.jpg"/></li>
		     			</ul>
		     		</div>
		     	</div>
                   <div class="bottom clearfloat">
		     		<p class="fl">菜单2 <span name="myPrice">10</span></p>
		     		<div class="you clearfloat fr">
		     			<ul>
		     				<li name="jianBtn"><img src="../images/jian.jpg"/></li>
		     				<li name="myCount">2</li>
		     				<li name="jiaBtn"><img src="../images/jia.jpg"/></li>
		     			</ul>
		     		</div>
		     	</div>
                        </div>
                      <div class="bottomall">
                        <p class="tit">午餐预定</p>
                         	<div class="bottom clearfloat">
                                
		     		<p class="fl">菜单1 <span name="myPrice">10</span></p>
		     		<div class="you clearfloat fr">
		     			<ul>
		     				<li name="jianBtn"><img src="../images/jian.jpg"/></li>
		     				<li name="myCount">1</li>
		     				<li name="jiaBtn"><img src="../images/jia.jpg"/></li>
		     			</ul>
		     		</div>
		     	</div>
                   <div class="bottom clearfloat">
		     		<p class="fl">菜单2 <span name="myPrice">10</span></p>
		     		<div class="you clearfloat fr">
		     			<ul>
		     				<li name="jianBtn"><img src="../images/jian.jpg"/></li>
		     				<li name="myCount">2</li>
		     				<li name="jiaBtn"><img src="../images/jia.jpg"/></li>
		     			</ul>
		     		</div>
		     	</div>
                          </div>
                        </div>--%>
                    <div class="confirm clearfloat">
                        <div class="gmshu clearfloat box-s fl">
                            <p class="fr">共<span name="count">0</span>件商品   合计￥<samp name="sum" id="sum">0</samp></p>
                        </div>
                    </div>
                </div>
            </div>
            <a href="#" onclick="submit()" class="shop-btn db" id="determine">确定</a>
        </div>
   <div style="display: none;"   id="dialog">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__hd"><strong class="weui-dialog__title">提示</strong></div>
        <div class="weui-dialog__bd"></div>
        <div class="weui-dialog__ft">
            <a  href="javascript:$('#dialog').hide();" class="weui-dialog__btn weui-dialog__btn_primary" id="que">确定</a>
        </div>
    </div>
</div>
       <div id="toast" style="display: none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast">
        <i class="weui-icon-success-no-circle weui-icon_toast"></i>
        <p class="weui-toast__content">订餐成功！</p>
    </div>
</div>
        <!--footer star-->
        <footer class="page-footer fixed-footer" id="footer">
            <ul>
               <%-- <li>
                    <a href="index.html">
                        <i class="iconfont icon-shouye" style=""></i>
                        <p>首页</p>
                    </a>
                </li>--%>
                <li class="active" >
                    <a href="#">
                        <i class="iconfont icon-icon04"></i>
                        <p>在线订餐</p>
                    </a>
                </li>
                <li class="right">
                    <%--openid=<%=openid%>"--%>
                    <a href="#" id="OrderList">
                        <i class="iconfont icon-gouwuche"></i>
                        <p>我的订餐</p>
                    </a>
                </li>
               <%-- <li>
                    <a href="login.html">
                        <i class="iconfont icon-yonghuming"></i>
                        <p>个人中心</p>
                    </a>
                </li>--%>
            </ul>
        </footer>
        <!--footer end-->
</body>
    <script src="../Script/mui.min.js"></script>
<script src="../Script/others.js"></script>
<script type="text/javascript" src="../Script/hmt.js"></script>
<script src="../Script/slick/slick.js" type="text/javascript"></script>
<script src="../Script/shopcar.js"></script>
<!--插件-->
<link rel="stylesheet" href="../css/swiper.min.css">
<script src="../Script/swiper.jquery.min.js"></script>
</html>
